package com.bndg.shu.shuyinyangshi.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.bndg.shu.shuyinyangshi.activitys.MainActivity;
import com.bndg.shu.shuyinyangshi.ui.FloatView;
import com.orhanobut.logger.Logger;


/**
 * Created by r on 17/3/15.
 */

public class FloatViewService extends Service {

    private FloatView mFloatView;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Logger.d("绑定了服务");
        return new FloatViewServiceBinder();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        MainActivity.IS_OPEN_SERVICE = true;
        Logger.d("开启了服务");
        mFloatView = new FloatView(this);
        mFloatView.show();
    }

    public class FloatViewServiceBinder extends Binder {
        public FloatViewService getService() {
            return FloatViewService.this;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        destroyFloat();
    }

    public void destroyFloat() {
        if ( mFloatView != null ) {
            mFloatView.destroy();
        }
        mFloatView = null;
    }
}
